package com.example.applicationview.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

/**
 * 测试 path.op
 */
public class PathOpView extends BaseView{

    public PathOpView(Context context) {
        super(context);
    }

    public PathOpView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int x = 80;
        int r = 100;

        canvas.translate(250,0);

        Path path1 = new Path();
        Path path2 = new Path();
        Path pathOpResult = new Path();

        path1.addCircle(-x, 0, r, Path.Direction.CW);
        path2.addCircle(x, 0, r, Path.Direction.CW);

        pathOpResult.op(path1,path2, Path.Op.DIFFERENCE);
        canvas.translate(0, 200);
        canvas.drawText("DIFFERENCE", 240,0,mPaint);
        canvas.drawPath(pathOpResult,mPaint);

        pathOpResult.op(path1,path2, Path.Op.REVERSE_DIFFERENCE);
        canvas.translate(0, 300);
        canvas.drawText("REVERSE_DIFFERENCE", 240,0,mPaint);
        canvas.drawPath(pathOpResult,mPaint);

        pathOpResult.op(path1,path2, Path.Op.INTERSECT);
        canvas.translate(0, 300);
        canvas.drawText("INTERSECT", 240,0,mPaint);
        canvas.drawPath(pathOpResult,mPaint);

        pathOpResult.op(path1,path2, Path.Op.UNION);
        canvas.translate(0, 300);
        canvas.drawText("UNION", 240,0,mPaint);
        canvas.drawPath(pathOpResult,mPaint);

        pathOpResult.op(path1,path2, Path.Op.XOR);
        canvas.translate(0, 300);
        canvas.drawText("XOR", 240,0,mPaint);
        canvas.drawPath(pathOpResult,mPaint);
    }
}
